home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / tweak16b.zip / TESTPAT.CPP < prev    next >
C/C++ Source or Header  |  1993-11-27  |  11KB  |  441 lines

  1. /*
  2.     testpat.cpp version 1.6
  3.     by Robert Schmidt of Ztiff Zox Softwear 1993
  4.  
  5.     Defines the member functions of the TestPatterns class declared in
  6.         testpat.hpp.
  7.  
  8.     1.1
  9.         Fixed a couple of bugs in the text mode test.  On some computers
  10.         it would overwrite data in the C000h segment, if RAM had been mapped
  11.         there by QEMM or something similar.
  12.  
  13.     Modified June 13-14, 1993 by Peter McDermott
  14.         The 16 color test pattern has been changed.  Now it puts dots from the
  15.         upper left hand corner to down the top and left of the screen to the
  16.         edges.  There is a longer, white dot every 100 pixels.  Also, a color
  17.         bar is displayed across the page.
  18.  
  19.     1.6
  20.         Added support for the mode autodetecting scheme, and for VGALIB,
  21.         my mode independant VGA graphics library, to provide more
  22.         intelligent test screens.
  23. */
  24.  
  25. #include <dos.h>
  26. #include <mem.h>
  27. #include <conio.h>
  28. #include <math.h>
  29. #include <string.h>
  30. #include <iostream.h>
  31. #include <stdio.h>
  32.  
  33. #include "misc.hpp"
  34. #include "screen.hpp"
  35. #include "vgalib.hpp"
  36. #include "testpat.hpp"
  37. #include "detect.hpp"
  38. #include "screen.hpp"
  39.  
  40. extern char *graphScr;
  41. extern unsigned *textScr;
  42. extern unsigned editHeight;
  43.  
  44. // These are the text strings identifying each test to the user.
  45.  
  46. char *TestPatterns::string[TestPatterns::tests] =
  47.     {
  48.     "Graphics autodetect",
  49.     "Text screen, 16 point",
  50.     "Text screen, 8 point",
  51.     "4 planes, 16 colors",
  52.     "1 plane, 256 colors",
  53.     "4 planes, 256 colors"
  54.     };
  55.  
  56.  
  57. void color16(unsigned char color)                    // Peter
  58. {
  59.   // load set/reset register with color to be displayed
  60.   outport(0x3ce,color<<8);
  61. }
  62.  
  63. // following is a point routine for 16 color mode
  64. void init16()                                        // Peter
  65. {
  66.   // default drawing color is white
  67.   color16(15);
  68.   // load set/reset enable for all display planes
  69.   outport(0x3ce,0x0f01);
  70.   // load map mask register for all display planes
  71.   outport(0x3c4,0x0f02);
  72.   // load function select correctly (logical OR)
  73.   outport(0x3ce,0x2003);
  74.   // set to read mode 0
  75.   outportb(0x3ce,0x05);
  76.   int ModeReg=inportb(0x3cf);
  77.   outport(0x3ce,ModeReg && 0xf7);  // make sure we're in read mode 0
  78. }
  79.  
  80.  
  81. void point16(unsigned int x, unsigned int y)        // Peter
  82. {
  83.   outportb(0x3d4,0x13);                //get screen width in words
  84.   unsigned width=inportb(0x3d5)*2;    //convert to bytes
  85.   // load bitmask register with correct value
  86.   outport(0x3ce,(0x80 >> (x % 8) << 8) | 0x08);
  87.   // load the latch register with the data already in display memory
  88.   _AX=graphScr[y*width+x/8];
  89.   // calculate the position in memory of the pixel to be written
  90.   graphScr[y*width+x/8] = 0x00;
  91. }
  92.  
  93.  
  94. // TestPatterns::run() puts the selected test onto the screen.
  95.  
  96. void TestPatterns::run(RegisterTable ®Tab)
  97.     {
  98.     unsigned a,c;
  99.     unsigned long offset;
  100.  
  101.     regTab.out();
  102.  
  103.     outportb(0x3c4,0x02);                //get write plane enable
  104.     unsigned plane=inportb(0x3c5);
  105.  
  106.     outportb(0x3d4,0x13);                //get screen width in words
  107.     unsigned long width=inportb(0x3d5)*2;    //convert to bytes
  108.  
  109.     // Now select the correct initialization method:
  110.  
  111.     switch (testNo)
  112.         {
  113.         case test4x16:
  114.         case test1x256:
  115.         case test4x256:
  116.             // All graphics modes: clear the screen, but take care of
  117.             //    write enabling all planes.
  118.             outport(0x3c4,0x0f02);
  119.             memset(graphScr, 0, 0xffff);
  120.             graphScr[0xffff] = 0;
  121.             outportb(0x3c4,0x02);
  122.             outportb(0x3c5,plane);
  123.             break;
  124.  
  125.         case testText16:                // set 8x16 font
  126.             _AX = 0x1104;
  127.             _BL = 0;
  128.             geninterrupt(0x10);
  129.             goto commonText;
  130.         case testText8:                    // set 8x8 font
  131.             _AX = 0x1102;
  132.             _BL = 0;
  133.             geninterrupt(0x10);
  134. commonText:
  135.             // Just blank the text screen.
  136.             memset(textScr, 0, 8000);
  137.         }
  138.  
  139.     switch (testNo)
  140.         {
  141.         case autoDetect:
  142.             ModeInfo minfo(regTab);
  143.             GraphicsAPI *g = minfo.getGraphicsAPI();
  144.             if (!g)
  145.                 {
  146.                 setBiosMode(3);
  147.                 cout << "This is not a graphics mode.  Either: -" << endl
  148.                      << " - Use TAB (->|) to select one of the two "
  149.                         "available text screens," << endl
  150.                      << " - Base your mode on one of the BIOS graphics "
  151.                         "modes, by pressing B and " << endl
  152.                      << "   typing a graphics mode number, for example "
  153.                         "0x12 or 0x13, or" << endl
  154.                      << " - Load a graphics mode file by pressing L and "
  155.                         "typing the name of the file." << endl << endl
  156.                      << "Now press any key to return to the editor." << endl;
  157.                 getch();
  158.                 }
  159.             else
  160.                 {
  161.                 g->setColor(0);
  162.                 g->wipe();
  163.                 int width = g->getVirtualWidth();
  164.                 int height = g->getVirtualHeight();
  165.                 int colors = g->getColors();
  166.                 char txt1[40];
  167.                 int i, j, maxTick = max(width, height);
  168.  
  169.                 if (g->getColors() == 256)
  170.                     setPalette256();
  171.                 else
  172.                     setPalette16();
  173.  
  174.                 for (i = 2; i <= maxTick; i += 2)
  175.                     {
  176.                     int coord = i-1;
  177.                     int color, length;
  178.                     if (i % 10 == 0)
  179.                         if (i % 50 == 0)
  180.                             if (i % 100 == 0)
  181.                                 {
  182.                                 color = 15, length = 10;
  183.                                 itoa(i, txt1, 10);
  184.                                 }
  185.                             else
  186.                                 color = 14, length = 7;
  187.                         else
  188.                             color = 13, length = 5;
  189.                     else
  190.                         color = 9, length = 2;
  191.                     if (i <= width)
  192.                         {
  193.                         g->setColor(color);
  194.                         g->vLine(coord, 0, length);
  195.                         if (length == 10)
  196.                             {
  197.                             g->setTextJustify(GraphicsAPI::RIGHT,
  198.                                               GraphicsAPI::TOP);
  199.                             g->putText(coord, length, txt1);
  200.                             }
  201.                         }
  202.                     if (i <= height)
  203.                         {
  204.                         g->setColor(color);
  205.                         g->hLine(0, coord, length);
  206.                         if (length == 10)
  207.                             {
  208.                             g->setTextJustify(GraphicsAPI::LEFT,
  209.                                               GraphicsAPI::BOTTOM);
  210.                             g->putText(length, coord, txt1);
  211.                             }
  212.                         }
  213.                     }
  214.  
  215.                 int middle = width/2;
  216.                 int line = 30;
  217.                 g->setTextJustify(GraphicsAPI::HCENTER, GraphicsAPI::TOP);
  218.                 g->setColor(10);
  219.                 g->putText(middle, line, g->getLibID());
  220.                 g->setColor(12);
  221.                 g->putText(middle, line+=12, "Physical resolution");
  222.                 sprintf(txt1, "%d x %d", g->getWidth(), g->getHeight());
  223.                 g->setColor(15);
  224.                 g->putText(middle, line+=9, txt1);
  225.  
  226.                 g->setColor(12);
  227.                 g->putText(middle, line+=12, "Virtual resolution");
  228.                 sprintf(txt1, "%d x %d", width, height);
  229.                 g->setColor(15);
  230.                 g->putText(middle, line+=9, txt1);
  231.  
  232.                 g->setColor(12);
  233.                 g->putText(middle, line+=12, "Page resolution");
  234.                 sprintf(txt1, "%3.1f x %3.1f", minfo.xpages, minfo.ypages);
  235.                 g->setColor(15);
  236.                 g->putText(middle, line+=9, txt1);
  237.  
  238.                 int hPalSize = width - 40;
  239.                 int vPalSize = height - (line+=22);
  240.                 int palSide = sqrt(colors);
  241.                 int hPalPix = hPalSize/palSide;
  242.                 int vPalPix = vPalSize/palSide;
  243.                 hPalSize = palSide * hPalPix + 1;
  244.                 vPalSize = palSide * vPalPix + 1;
  245.                 for (i = 0; i < colors; ++i)
  246.                     {
  247.                     g->setColor(i);
  248.                     int x = width-hPalSize+(i/palSide)*hPalPix;
  249.                     int y = height-vPalSize+(i%palSide)*vPalPix;
  250.                     g->bar(x, y, x+hPalPix, y+vPalPix);
  251.                     }
  252.  
  253.                 int basex=0, basey=0, bdirx=0, bdiry=0, quit=0;
  254.                 while (!quit)
  255.                     {
  256.                     if (kbhit())
  257.                         {
  258.                         int key = getch();
  259.                         if (!key && kbhit())
  260.                             key = getch() << 8;
  261.  
  262.                         switch (key)
  263.                             {
  264.                             case 0x4700:
  265.                                 basex = basey = bdirx = bdiry = 0;
  266.                                 break;
  267.                             case 0x4800:            //UP
  268.                                 --bdiry;
  269.                                 break;
  270.                             case 0x4b00:
  271.                                 --bdirx;
  272.                                 break;
  273.                             case 0x4c00:
  274.                                 bdirx = bdiry = 0;
  275.                                 break;
  276.                             case 0x4d00:
  277.                                 ++bdirx;
  278.                                 break;
  279.                             case 0x5000:            //DOWN
  280.                                 ++bdiry;
  281.                                 break;
  282.                             case 27:
  283.                             case 13:
  284.                                 quit = 1;
  285.                                 break;
  286.                             }
  287.                         }
  288.                     basex += bdirx;
  289.                     basey += bdiry;
  290.                     if (basex > width-g->getWidth())
  291.                         basex = width-g->getWidth(), bdirx = 0;
  292.                     if (basey > height-g->getHeight())
  293.                         basey = height-g->getHeight(), bdiry = 0;
  294.                     if (basex < 0)
  295.                         basex = bdirx = 0;
  296.                     if (basey < 0)
  297.                         basey = bdiry = 0;
  298.  
  299.                     g->setBase(basex, basey);
  300. //                    bdirx = bdiry = 0;            // for debugging
  301.                     }
  302.                 delete g;
  303.                 }
  304.             break;
  305.  
  306.         case testText16:
  307.         case testText8:
  308.  
  309.             // Fill top line with the sequence "0123456789" lt grey/black:
  310.             a = 0;
  311.             for (c=0; c<width; c++)
  312.                 textScr[a++] =